<?php
// 获得未来七天预约信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("d_getLoginInfo.php");
//设置中国时区
date_default_timezone_set('Asia/Shanghai');
// 获取当前日期
$getNowDate = date('Y-m-d');
// 获取当前日期所对应的时间戳
$getNowDateTimestamp = strtotime($getNowDate);

// 开始输出头部<li>标签
echo "
    <div class='accept-info-div-top'>
    <ul class='top-ul'>
    <li class='top-li current '>" . $getNowDate . "</li>";
for ($i = 0; $i < 6; $i++) {
    $getNowDateTimestamp += 86400;
    $getNextDate = date('Y-m-d', $getNowDateTimestamp);
    echo "<li class='top-li'>" . $getNextDate . "</li>";
}
echo "</ul></div>";




// 开始输出内容部分
echo "<div class='accept-info-div-down'>";

for ($i = 0; $i < 7; $i++) {
    if ($i == 0) {
        $default_style = "style='display: block;'";
    } else {
        $default_style = "";
    }
    echo "<div class='info-div-item' " . $default_style . ">";
    // 查询每天的预约信息
    $selectDay = "SELECT * FROM order_infos JOIN department_infos ON order_infos.orderType = department_infos.department_ID WHERE doc_ID = '" . $doc_ID . "' AND orderDate = '" . $getNowDate . "' ORDER BY orderTime ASC";
    if ($result_selectDay = mysqli_query($connect_DB, $selectDay)) {
        $num_selectDay = mysqli_num_rows($result_selectDay);
        
        // 如果当天有预约记录
        if ($num_selectDay > 0) {
            // 循环输出当天预约记录
            while ($row_selectDay = mysqli_fetch_object($result_selectDay)) {
                // 查询对应的用户和宠物信息
                $selectUser = "SELECT * FROM user_infos WHERE user_ID = '" . $row_selectDay->user_ID . "'";
                $selectPet = "SELECT * FROM pet_infos WHERE pet_ID = '" . $row_selectDay->pet_ID . "'";
                $result_selectUser = mysqli_query($connect_DB, $selectUser);
                $result_selectPet = mysqli_query($connect_DB, $selectPet);
                if ($result_selectUser && $result_selectPet) {
                    $row_selectUser = mysqli_fetch_object($result_selectUser);
                    $row_selectPet = mysqli_fetch_object($result_selectPet);
                    if (substr($row_selectPet->pet_PhotoAddress, 0, 3) == "pet") {
                        $pet_photo_src = "../public/pic/pet_photos/" . $row_selectDay->user_ID . "/" . $row_selectPet->pet_PhotoAddress;
                    } else {
                        $pet_photo_src = "../public/pic/pet_photos/" . $row_selectPet->pet_PhotoAddress;
                    }

                    if ($row_selectDay->orderState == 0) {
                        $btn = "<a target=_blank' href='d_CancelOrder.php?orderID=" . $row_selectDay->orderID . "'><button type='button' class='btn btn-outline-danger btnstyle'>取消预约</button></a>";
                        $state = "<b style='color:red;'>用户取消预约</b>";
                    } else {
                        $btn = "<a target=_blank' href='doc_ResultUpload.php?orderID=" . $row_selectDay->orderID . "'><button type='button' class='btn btn-outline-success btnstyle'>填写诊单</button></a>";
                        $state = "<b style='color:green;'>已预约待接诊</b>";
                    }
                    echo "
                        <div class='info-div-item-notnull'>
                            <div class='info-div-item-left'>
                                <img src='" . $pet_photo_src . "'>
                            </div>
                            <div class='info-div-item-center'>
                                <div class='item-center-left'>
                                    <p><span>预约ID：</span>" . $row_selectDay->orderID . "</p>
                                    <p><span>宠物昵称：</span>" . $row_selectPet->pet_Name . "</p>
                                    <p><span>宠物类型：</span>" . $row_selectPet->pet_Type . "</p>
                                    <p><span>预约项目：</span>" . $row_selectDay->orderType . " - " . $row_selectDay->department_Name . "</p>
                                    <p><span>预约时间：</span>" . $row_selectDay->orderTime . "</p>
                                    <p><span>预约状态：</span>" . $state . "</p>
                                </div>
                                <div class='item-center-right'>
                                    <p><span>宠物主人：</span>" . $row_selectUser->user_Name . "</p>
                                    <p><span>联系电话：</span>" . $row_selectDay->phone . "</p>
                                    <p><span>提交时间：</span>" . $row_selectDay->subDate . "</p>
                                    <p><span>预约备注：</span>" . $row_selectDay->orderRemark . "</p>
                                    <p class='remark-p'></p>
                                </div>
                            </div>
                            <div class='info-div-item-right'>" . $btn . "</div>
                        </div>
                        ";
                } else {
                    echo "查询数据失败！<br>" . $selectUser . "<br>" . $selectPet;
                }
            }
        } else {
            // 如果当天没有预约
            echo "
                    <div class='info-div-item-null'>
                           当天暂无预约信息
                    </div>
                ";
        }
        echo "</div>";
    } else {
        echo "查询数据失败！<br>" . $selectDay;
    }
    $getNowDateTimestamp = strtotime($getNowDate);
    $getNowDateTimestamp += 86400;
    $getNowDate = date('Y-m-d', $getNowDateTimestamp);
}
echo "</div>";


$connect_DB->close();
?>